﻿using System;
using System.Collections.Generic;
using BotonJXC.Entity;
using StoreDAO = BotonJXC.DAO.StoreDAO;
using BotonJXC.Util;
using NHibernate.Criterion;

namespace BotonJXC.BLL
{
    public class StoreBLL : BaseBLL<StoreDAO, Store, int>
    {
        public StoreBLL()
        {
        }

        public PageModel<Store> Find(string storeName, short storeLevel, int start, int count)
        {
            List<ICriterion> criterions = new List<ICriterion>();
            if (!string.IsNullOrEmpty(storeName))
            {
                criterions.Add(Restrictions.Like("StoreName", storeName, MatchMode.Anywhere));
            }
            if (storeLevel > 0)
            {
                criterions.Add(Restrictions.Eq("StoreLevel", storeLevel));
            }
            return Dao.FindByPage(criterions.ToArray(), null, start, count);
        }

        public IList<Store> findStore(Store store)
        {
            List<ICriterion> criterions = new List<ICriterion>();
            if (store.StoreType > 0) {
                criterions.Add(Restrictions.Eq("StoreType", store.StoreType));
            }
            return Dao.Find(criterions.ToArray());
        }
    }
}